package com.wyz.controller;

import com.wyz.bpo.PersonManagerBPO;
import com.wyz.model.dto.PersonQueryDTO;
import com.wyz.model.query.PersonAddQuery;
import com.wyz.model.query.PersonDeleteQuery;
import com.wyz.model.query.PersonQuery;
import com.wyz.util.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 无涯子
 * @version 1.0
 * @date 2023/5/14 15:02:07
 * @description PersonManager控制器,主要进行封装处理，处理前后端交互，不处理逻辑
 */
@RestController
@RequestMapping("/api/v1")
@Api(value = "人员管理")
public class PersonManageController {
    @Resource
    private PersonManagerBPO personManagerBPO;

    @ApiOperation(value = "查询人员列表")
    @GetMapping("/person")
    public ResponseResult queryPerson(PersonQuery personQuery){
        return ResponseResult.success(personManagerBPO.queryPerson(personQuery));
    }

    @ApiOperation(value = "根据ID查询人员信息")
    @PutMapping("/person")
    public ResponseResult updatePersonById(@RequestBody PersonAddQuery personAddQuery){
        return ResponseResult.success(personManagerBPO.updatePerson(personAddQuery));
    }
    @ApiOperation(value = "批量更新人员信息")
    @PutMapping("/persons")
    public ResponseResult updatePersonBatchById(@RequestBody List<PersonQueryDTO> personQueryDTOList){
       return personManagerBPO.updatePersonBatchById(personQueryDTOList) ? ResponseResult.success("更新成功") : ResponseResult.fail("更新失败");
    }
    @ApiOperation(value = "注销人员信息")
    @DeleteMapping("/person")
    public ResponseResult deletePersonById(@RequestBody PersonDeleteQuery personDeleteQuery){
        return ResponseResult.success(personManagerBPO.deletePersonById(personDeleteQuery));
    }
    @ApiOperation(value = "新增人员信息")
    @PostMapping("/person")
    public ResponseResult addPerson(@RequestBody PersonAddQuery personAddQuery){
       return ResponseResult.success(personManagerBPO.addPerson(personAddQuery));
    }

}
